#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
class Solution {
public:
    int maxEnvelopes(vector<vector<int>>& envelopes) {
        sort(envelopes.begin(), envelopes.end(), [](vector<int>& a1, vector<int>& a2) {return a1[0] < a2[0]; });
        int n = envelopes.size();
        vector<int> ans(n, 1);
        for (int i = 1; i < n; ++i)
            for (int j = i - 1; j >= 0; --j) {
                if (envelopes[i][0] > envelopes[j][0] && envelopes[i][1] > envelopes[j][1])
                    ans[i] = max(ans[i], ans[j] + 1);
            }
        int a = 0;
        for (auto& e : ans)
            a = max(a, e);
        return a;
    }
};
int main() {
    vector<vector<int>> ans{ {5,4},{6,4},{6,7},{2,3} };
    Solution().maxEnvelopes(ans);
}